/**
 * 
 */
package se.cirrus.base.com;

import java.util.concurrent.ConcurrentLinkedQueue;

import se.cirrus.base.error.*;
import se.cirrus.base.struct.*;

/**
 * This is an interface representing a bi-directional communication channel with one other node.
 * A communicator may or may not be implemented as several threads
 * 
 * @author Winquman
 * 
 */
public interface Communicator {
	
	/**
	 * Sends a message to the remote node.
	 * 
	 * @param message Message to send
	 * @throws CommunicationException If the message could not be sent
	 * @throws InvalidStateException if the channel is not open
	 */
	public void send(Message message) throws CommunicationException, InvalidStateException;
	
	/**
	 * Sets a message queue for incoming messages from this communication line.
	 * 
	 * @param mq The message queue to put new messages in
	 * @throws InvalidStateException if the incoming communication channel is already open
	 */
	public void setIncomingQueue(ConcurrentLinkedQueue<Message> mq) throws InvalidStateException;
	
	/**
	 * 
	 * @return the state of this Communicator
	 */
	public CommunicationState getState();
	
	/**
	 * 
	 * @throws CommunicationException
	 * @throws InvalidStateException
	 */
	public void connect() throws CommunicationException, InvalidStateException;
	
	/**
	 * 
	 * @throws CommunicationException
	 * @throws InvalidStateException
	 */
	public void disconnect() throws CommunicationException, InvalidStateException;
	
	
	public Message getNext() throws CommunicationException, InvalidStateException;
}
